define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'task_order/index/ids/'+Config.ids + location.search,
                    
                    table: 'task_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: false,
                search:false,
                showColumns:false,
                showExport:false,
                commonSearch:false,
                pageSize: 10,
                showToggle: false,
                columns: [
                    [
                        {field: 'volunteer.name', title: '義工姓名'},
                        {field: 'upload_images', title: '上傳圖片',width:'30%', events: Table.api.events.image, formatter: Table.api.formatter.images, operate: false},
                        {field: 'content', title: '任務完成說明'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'score', title: __('Score'), operate:'BETWEEN'},
                        {field: 'completiontime', title: __('Completiontime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});